package com.lecture.java8.excel.dyr.b;

import com.alibaba.excel.EasyExcel;
import com.lecture.java8.excel.DemoDataListener;
import com.lecture.java8.excel.dyr.a.Model0423;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test0424 {
    public static void main(String[] args) {
        String dir = "D:\\study\\tmp\\0424\\";


        String result1 = dir + "1最终结果-企业生命周期.xlsx";
        DemoDataListener<Result0424_1> dataResultListener = new DemoDataListener<>();
        EasyExcel.read(result1, Result0424_1.class,dataResultListener).sheet().doRead();
        //全要素生产率
        List<Result0424_1> resultList = dataResultListener.getDataList();
        Map<String, Result0424_1> map1 = new HashMap<>();
        for (Result0424_1 result : resultList) {
            map1.put(result.getA() + "-" + result.getB(),result);
        }

        String result2 = dir + "2董事会人数.xlsx";
        DemoDataListener<Result0424_2> dataResultListener2 = new DemoDataListener<>();
        EasyExcel.read(result2, Result0424_2.class,dataResultListener2).sheet().doRead();
        //全要素生产率
        List<Result0424_2> resultList2 = dataResultListener2.getDataList();
        Map<String, Result0424_2> map2 = new HashMap<>();
        for (Result0424_2 result : resultList2) {
            map2.put(result.getA() + "-" + result.getB().substring(0,4),result);
        }

        String result3 = dir + "3股权性质.xlsx";
        DemoDataListener<Result0424_3> dataResultListener3 = new DemoDataListener<>();
        EasyExcel.read(result3, Result0424_3.class,dataResultListener3).sheet().doRead();
        //全要素生产率
        List<Result0424_3> resultList3 = dataResultListener3.getDataList();
        Map<String, Result0424_3> map3 = new HashMap<>();
        for (Result0424_3 result : resultList3) {
            map3.put(result.getA() + "-" + result.getB().substring(0,4),result);
        }

        String dataResultFileName = dir + "显著性0.004的(1).xlsx";
        DemoDataListener<Model0423> dataListener = new DemoDataListener<>();
        EasyExcel.read(dataResultFileName, Model0423.class,dataListener).sheet().doRead();
        List<Model0423> dataList = dataListener.getDataList();

        for (Model0423 model : dataList) {
            String key = model.getA() + "-" + model.getB();
            Result0424_1 r5 = map1.get(key);
            if (r5 != null) {
                model.setAj(r5.getC());
            }

            Result0424_2 r2 = map2.get(key);
            model.setAk(r2.getC());

            Result0424_3 r3 = map3.get(key);
            model.setAl(r3.getC());
        }

        EasyExcel.write(dir + "result0424-2.xlsx", Model0423.class)
                .sheet("a").doWrite(dataList);
    }
}
